<?php

namespace common\models\views;

use Yii;
use common\models\shop\ShopGoods;

/**
 * 标准化产品单元数据模型（SPU）
 * 
 * @author emhome<emhome@163.com>
 * @since 2.0
 */
class ViewSkuSpecMp extends ViewSkuSpec {

    /**
     * {@inheritdoc}
     */
    public static function sku($id) {
        $query = static::find()->alias('t')->where(['t.product_id' => $id]);
        $query->innerJoinWith([
            'goods g' => function ($query) {
                $query->active(ShopGoods::STATUS_ACTIVE);
            },
        ], false);
        return $query->all();
    }

    public function getTag() {
        return $this->spec_value_id;
    }

    /**
     * {@inheritdoc}
     */
    public function fields() {
        return [
            'id' => 'spec_value_id',
            'k_id' => 'spec_id',
            'k' => 'spec_name',
            'k_s' => function() {
                return 's' . $this->spec_id;
            },
            'name' => 'spec_value',
            'imgUrl' => 'thumb',
        ];
    }

}
